package com.momoauth.api_client.controller;

import com.momoauth.api_client.config.QiniuConfig;
import com.momoauth.common.core.result.ResponseResurt;
import com.momoauth.common.tps.qiniu.service.QiniuUploadService;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@RestController
@RequestMapping("/upload")
@Api(tags = "上传")
public class UploadController {

    /**
     * 上传文件
     * @param file
     * @return
     * @throws IOException
     */
    @RequestMapping(value = "/uploadFile", method = RequestMethod.POST)
    public ResponseResurt uploadFile(MultipartFile file) throws IOException {
        QiniuUploadService qiniuUploadService = new QiniuUploadService(
                QiniuConfig.domain,
                QiniuConfig.accessKey,
                QiniuConfig.secretKey,
                QiniuConfig.bucket
        );
        String fileName = qiniuUploadService.uploadFile(file);
        return ResponseResurt.success().data(fileName);
    }
}
